package com.example.core.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.core.entity.Attendance;
import com.example.core.entity.EmployeePO;
import com.example.core.service.AttendanceService;
import com.example.core.utils.Httputil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
public class AttendanceForSTFCrontabNew implements ApplicationRunner {

    @Resource
    private AttendanceService attendanceService;

    //测试API URL地址，仅为测试，实际请使用实际地址
    private static final String TEST_API_URL = "/JT/BA/BA-0222/APM/PRODUCT/list";
    // dev环境测试AppKey与appSecret 仅demo测试使用,实际使用时请使用erp方面对接人提供的
    private static final String devAppKey = "4badcea232a74f3d9ed4ed26bafb4262";
    private static final String devAppSecret = "75d9b929bb024f56a8eee1adce8fad7d";

    private static final String PROD_TEST_APPKEY = "42e823692a9d4fb2b24162eec9d45317";
    private static final String PROD_TEST_APP_SECRET = "14407228030a420486eedf9f61d2a861";
    //demo测试接口使用的idmid，仅为demo测试使用，业务中请使用实际需要的idmid
    private static final String DEV_TEST_IDMID = "u2020170348";
    public static final String DATE_FORMAT = "yyyy-MM-dd";

    /**
     * 定时修改有效日期
     */
    @SneakyThrows
//    @PostConstruct
    public void AttendanceForSTFCrontab(String time) {
        ObjectMapper objectMapper = new ObjectMapper();
        // 请求参数
//        String time = "2022-11-22";//当前时间
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        String time1 = time;
       /* Date currdate = format.parse(time);
        Calendar ca = Calendar.getInstance();
        ca.setTime(currdate);
        ca.add(Calendar.DATE, -1);
        currdate = ca.getTime();
        time = format.format(currdate);*/
        System.out.println("初始的时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()).toString());
        /******************************************restTemplate**************************************/
        //生成一个设置了连接超时时间、请求超时时间、异常重试次数3次
        RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(1000000).setConnectTimeout(1000000).setSocketTimeout(3000000).build();
        HttpClientBuilder builder = HttpClientBuilder.create().setDefaultRequestConfig(config).setRetryHandler(new DefaultHttpRequestRetryHandler(1, false));
        HttpClient httpClient = builder.build();
        ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        /******************************************restTemplate**************************************/
        /*所有人员*/
        List<Map<String,Object>> queryDayList = attendanceService.queryDingdingList(new EmployeePO());
        /*所有自定义列*/
        List<Map<String,Object>> querycolumList = attendanceService.querycolumList();
        /*所有假期类型*/
        List<String> queryleaveList = new ArrayList<>();
        queryleaveList.add("丧假");
        queryleaveList.add("事假");
        queryleaveList.add("产假");
        queryleaveList.add("产前检查假");
        queryleaveList.add("哺乳假");
        queryleaveList.add("婚假");
        queryleaveList.add("年假");
        queryleaveList.add("探亲假");
        queryleaveList.add("病假");
        queryleaveList.add("终止妊娠假");
        queryleaveList.add("调休");
        queryleaveList.add("陪产假");
        /*获取token*/
        JSONObject token = getAccessToken();
        String access_token = token.getString("access_token");
        //请求URL10.5.78.17:20087
        String zhidingurl = "http://10.5.78.17:20087/dingding/api";//访问智钉url10.5.1.11:28008
        String tokenurl = "/topapi/attendance/getcolumnval";//获取考勤信息url
        String usergroupurl = "/topapi/attendance/getusergroup";//获取考勤组url
        String leaveurl = "/topapi/attendance/getleavetimebynames";//请假信息url
        //考勤时间
        for(int j=0;j<queryDayList.size();j++){//所有人员
            try {
                Attendance attendanceForSTFPO = new Attendance();
                for(int x=0;x<querycolumList.size();x++){//所有自定义列
                    /******************************************考勤**************************************/
                    Map body=new HashMap();
                    Map requestbody=new HashMap();
                    requestbody.put("from_date",time+" 00:00:01");//起始时间
                    requestbody.put("to_date",time1+" 23:59:59");//结束时间
                    requestbody.put("userid",queryDayList.get(j).get("userid").toString());//userId
                    requestbody.put("column_id_list",querycolumList.get(x).get("columnVo").toString());//userId
                    body.put("path",tokenurl);//请求钉钉接口地址
                    body.put("request",requestbody);//请求参数
                    body.put("type","POST");//类型
                    //body.put("userIdList",Arrays.asList("000000994"));//userId
                    //请求头
                    HttpHeaders headers = new HttpHeaders();
                    headers.add("access_token",access_token);
                    HttpEntity<String> httpEntity = new HttpEntity(body,headers);
                    /******************************************考勤**************************************/
                    /******************************************考勤打卡时间**************************************/
                    ResponseEntity<Map> kqBody = restTemplate.exchange(zhidingurl, HttpMethod.POST, httpEntity, Map.class);//请假信息
                    Map kqjsons = kqBody.getBody();
                    JSONObject kqjson = new JSONObject(kqjsons);
                    JSONObject kqjson1 = kqjson.getJSONObject("result");
                    if (kqjson1 != null){
                        JSONArray kqjson2 = kqjson1.getJSONArray("column_vals");

                        JSONObject kqjson3 = objectMapper.convertValue(kqjson2.get(0), JSONObject.class);
                        JSONArray kqjson4 = kqjson3.getJSONArray("column_vals");
                        JSONObject kqjson5 = objectMapper.convertValue(kqjson4.get(0), JSONObject.class);
                        String value = kqjson5.getString("value");//结果
                        if(querycolumList.get(x).get("columnVo").toString().equals("80527513")){
                            attendanceForSTFPO.setBc(value);//班次
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527514")){
                            attendanceForSTFPO.setSbdksj1(value);//上班1打卡时间
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527515")){
                            attendanceForSTFPO.setSbdkjg1(value);//打卡结果
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527516")){
                            attendanceForSTFPO.setXbdksj1(value);//下班1打卡时间
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527517")){
                            attendanceForSTFPO.setXbdkjg1(value);//打卡结果
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527518")){
                            attendanceForSTFPO.setSbdksj2(value);//上班2打卡时间
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527519")){
                            attendanceForSTFPO.setSbdkjg2(value);//打卡结果
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527520")){
                            attendanceForSTFPO.setXbdksj2(value);//下班2打卡时间
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527521")){
                            attendanceForSTFPO.setXbdkjg2(value);//打卡结果
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527526")){
                            attendanceForSTFPO.setSpd (value);//关联的审批单
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527492")){
                            attendanceForSTFPO.setCqts(value);//出勤天数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527493")){
                            attendanceForSTFPO.setXxts(value);//休息天数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527494")){
                            attendanceForSTFPO.setGzsc(value);//工作时长(分钟)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527495")){
                            attendanceForSTFPO.setCdcs(value);//迟到次数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527496")){
                            attendanceForSTFPO.setCdsc(value);//迟到时长(分钟)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527497")){
                            attendanceForSTFPO.setYacdcs (value);//严重迟到次数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527498")){
                            attendanceForSTFPO.setYzcdsc (value);//严重迟到时长(分钟)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527499")){
                            attendanceForSTFPO.setKgcdts(value);//旷工迟到天数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527500")){
                            attendanceForSTFPO.setZtcs(value);//早退次数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527501")){
                            attendanceForSTFPO.setZtsc(value);//早退时长(分钟)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527502")){
                            attendanceForSTFPO.setSbqkcs (value);//上班缺卡次数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527503")){
                            attendanceForSTFPO.setXbqkcs (value);//下班缺卡次数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527504")){
                            attendanceForSTFPO.setKgts(value);//旷工天数
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527505")){
                            attendanceForSTFPO.setCc(value);//出差(天)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527506")){
                            attendanceForSTFPO.setYgwc(value);//因公外出
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527507")){
                            attendanceForSTFPO.setTxbg(value);//弹性办公(天)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527509")){
                            attendanceForSTFPO.setGzrjb(value);//工作日加班(小时)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527510")){
                            attendanceForSTFPO.setXxrjb(value);//休息日加班(小时)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80527511")){
                            attendanceForSTFPO.setJjrjb(value);//节假日加班(小时)
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617870")){
                            attendanceForSTFPO.setJbzsc(value);//加班总时长（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617871")){
                            attendanceForSTFPO.setGzrf(value);//工作日（转加班费）（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617872")){
                            attendanceForSTFPO.setXxrf(value);//休息日（转加班费）（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617873")){
                            attendanceForSTFPO.setJjrf(value);//节假日（转加班费）（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617874")){
                            attendanceForSTFPO.setGzrx(value);//工作日（转调休）（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617875")){
                            attendanceForSTFPO.setXxrx(value);//休息日（转调休）（小时）
                        }if(querycolumList.get(x).get("columnVo").toString().equals("80617876")){
                            attendanceForSTFPO.setJjrx(value);//节假日（转调休）（小时）
                        }
                    }
                }

                /******************************************考勤打卡时间**************************************/
                /******************************************请假***************************************/
                for(int l=0;l<queryleaveList.size();l++){
                    Map bodyleave=new HashMap();
                    Map requestbodyleave=new HashMap();
                    requestbodyleave.put("from_date",time+" 00:00:01");
                    requestbodyleave.put("to_date",time1+" 23:59:59");
                    requestbodyleave.put("leave_names",queryleaveList.get(l));
                    requestbodyleave.put("userid",nullObject2String(queryDayList.get(j).get("userid").toString()));//userid
                    bodyleave.put("path",leaveurl);//请求钉钉接口地址
                    bodyleave.put("request",requestbodyleave);//请求参数
                    bodyleave.put("type","POST");//类型
                    HttpHeaders headersleave = new HttpHeaders();
                    headersleave.add("access_token",access_token);
                    HttpEntity<String> httpEntityleave = new HttpEntity(bodyleave,headersleave);
                    ResponseEntity<Map> leaveBody = restTemplate.exchange(zhidingurl, HttpMethod.POST, httpEntityleave, Map.class);//请假信息
                    Map leavejsons = leaveBody.getBody();
                    JSONObject leavejson = new JSONObject(leavejsons);
                    JSONObject leavejson1 = leavejson.getJSONObject("result");
                    if (leavejson1 != null){
                        JSONArray leavejson2 = leavejson1.getJSONArray("columns");
                        JSONObject leavejson3 = objectMapper.convertValue(leavejson2.get(0), JSONObject.class);
                        JSONArray leavejson4 = leavejson3.getJSONArray("columnvals");
                        JSONObject leavejson5 = objectMapper.convertValue(leavejson4.get(0), JSONObject.class);
                        String leavehours = leavejson5.getString("value");//请假时长
                        if(queryleaveList.get(l).equals("丧假")){
                            attendanceForSTFPO.setSangj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("事假")){
                            attendanceForSTFPO.setSj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("产假")){
                            attendanceForSTFPO.setCj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("产前检查假")){
                            attendanceForSTFPO.setCqjcj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("哺乳假")){
                            attendanceForSTFPO.setBrj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("婚假")){
                            attendanceForSTFPO.setHj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("年假")){
                            attendanceForSTFPO.setNj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("探亲假")){
                            attendanceForSTFPO.setTqj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("病假")){
                            attendanceForSTFPO.setBj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("终止妊娠假")){
                            attendanceForSTFPO.setRsj(leavehours);
                        }
                        if(queryleaveList.get(l).equals("调休")){
                            attendanceForSTFPO.setTx(leavehours);
                        }
                        if(queryleaveList.get(l).equals("陪产假")){
                            attendanceForSTFPO.setPcj(leavehours);
                        }
                    }

                }
                /*******************************************请假*********************************************/
                /*******************************************考勤组******************************************/
                Map groupbody=new HashMap();
                Map requestgroupbody=new HashMap();
                requestgroupbody.put("userid",nullObject2String(queryDayList.get(j).get("userid").toString()));//userid
                groupbody.put("path",usergroupurl);//请求钉钉接口地址
                groupbody.put("request",requestgroupbody);//请求参数
                groupbody.put("type","POST");//类型
                HttpHeaders groupheaders = new HttpHeaders();
                groupheaders.add("access_token",access_token);
                HttpEntity<String> httpEntityGroup = new HttpEntity(groupbody,groupheaders);
                ResponseEntity<Map> groupBody = restTemplate.exchange(zhidingurl, HttpMethod.POST, httpEntityGroup, Map.class);//考勤组信息
                Map groupjsons = groupBody.getBody();
                JSONObject groupjson = new JSONObject(groupjsons);
                /******************************************考勤组*****************************************/
                String groupName = groupjson.getJSONObject("result").getString("name");//考勤组名称
                //String groupId = groupjson.getJSONObject("result").getString("group_id");//考勤组id
                String realname = nullObject2String(queryDayList.get(j).get("realname"));//姓名
                String account = nullObject2String(queryDayList.get(j).get("account"));//账号
                String userid = nullObject2String(queryDayList.get(j).get("userid"));//姓名
                String hrid = nullObject2String(queryDayList.get(j).get("hrid"));//id
                String mobile = nullObject2String(queryDayList.get(j).get("mobile"));//电话
                String supplier = nullObject2String(queryDayList.get(j).get("supplier"));//公司
                String product = nullObject2String(queryDayList.get(j).get("product"));//产品
                String productline = nullObject2String(queryDayList.get(j).get("productline"));//产品线
                String field = nullObject2String(queryDayList.get(j).get("field"));//领域
                String workdate = time;  //打卡日期

                Attendance up = new Attendance();
                up.setName(realname);//姓名
                up.setAccount(account);//账号
                up.setHrid(hrid);//id
                up.setUserid(userid);
                up.setPhone(mobile);//电话
                up.setCompany(supplier);//公司
                up.setWorkgroup(groupName);//考勤组名称
                up.setField(field);//领域
                up.setProduct(product);//产品
                up.setProductline(productline);//产品线
                up.setWorkdate(workdate);//打卡日期
                up.setBc(attendanceForSTFPO.getBc());//班次
                up.setSbdksj1(attendanceForSTFPO.getSbdksj1());//上班1打卡时间
                up.setSbdkjg1(attendanceForSTFPO.getSbdkjg1());//打卡结果
                up.setXbdksj1(attendanceForSTFPO.getXbdksj1());//下班1打卡时间
                up.setXbdkjg1(attendanceForSTFPO.getXbdkjg1());//打卡结果
                up.setSbdksj2(attendanceForSTFPO.getSbdksj2());//上班2打卡时间
                up.setSbdkjg2(attendanceForSTFPO.getSbdkjg2());//打卡结果
                up.setXbdksj2(attendanceForSTFPO.getXbdksj2());//下班2打卡时间
                up.setXbdkjg2(attendanceForSTFPO.getXbdkjg2());//打卡结果
                up.setSpd(attendanceForSTFPO.getSpd());//关联的审批单
                up.setCqts(attendanceForSTFPO.getCqts());//出勤天数
                up.setXxts(attendanceForSTFPO.getXxts());//休息天数
                up.setGzsc(attendanceForSTFPO.getGzsc());//工作时长(分钟)
                up.setCdcs(attendanceForSTFPO.getCdcs());//迟到次数
                up.setCdsc(attendanceForSTFPO.getCdsc());//迟到时长(分钟)
                up.setYacdcs(attendanceForSTFPO.getYacdcs());//严重迟到次数
                up.setYzcdsc(attendanceForSTFPO.getYzcdsc());//严重迟到时长(分钟)
                up.setKgcdts(attendanceForSTFPO.getKgcdts());//旷工迟到天数
                up.setZtcs(attendanceForSTFPO.getZtcs());//早退次数
                up.setZtsc(attendanceForSTFPO.getZtsc());//早退时长(分钟)
                up.setSbqkcs(attendanceForSTFPO.getSbqkcs());//上班缺卡次数
                up.setXbqkcs(attendanceForSTFPO.getXbqkcs());//下班缺卡次数
                up.setKgts(attendanceForSTFPO.getKgts());//旷工天数
                up.setCc(attendanceForSTFPO.getCc());//出差(天)
                up.setYgwc(attendanceForSTFPO.getYgwc());//因公外出
                up.setTxbg(attendanceForSTFPO.getTxbg());//弹性办公(天)
                up.setGzrjb(attendanceForSTFPO.getGzrjb());//工作日加班(小时)
                up.setXxrjb(attendanceForSTFPO.getXxrjb());//休息日加班(小时)
                up.setJjrjb(attendanceForSTFPO.getJjrjb());//节假日加班(小时)
                up.setJbzsc(attendanceForSTFPO.getJbzsc());//加班总时长（小时）
                up.setGzrf(attendanceForSTFPO.getGzrf());//工作日（转加班费）（小时）
                up.setXxrf(attendanceForSTFPO.getXxrf());//休息日（转加班费）（小时）
                up.setJjrf(attendanceForSTFPO.getJjrf());//节假日（转加班费）（小时）
                up.setGzrx(attendanceForSTFPO.getGzrx());//工作日（转调休）（小时）
                up.setXxrx(attendanceForSTFPO.getXxrx());//休息日（转调休）（小时）
                up.setJjrx(attendanceForSTFPO.getJjrx());//节假日（转调休）（小时）
                up.setSangj(attendanceForSTFPO.getSangj());
                up.setSj(attendanceForSTFPO.getSj());
                up.setCj(attendanceForSTFPO.getCj());
                up.setCqjcj(attendanceForSTFPO.getCqjcj());
                up.setBrj(attendanceForSTFPO.getBrj());
                up.setHj(attendanceForSTFPO.getHj());
                up.setNj(attendanceForSTFPO.getNj());
                up.setTqj(attendanceForSTFPO.getTqj());
                up.setBj(attendanceForSTFPO.getBj());
                up.setRsj(attendanceForSTFPO.getRsj());
                up.setTx(attendanceForSTFPO.getTx());
                up.setPcj(attendanceForSTFPO.getPcj());
                attendanceService.save(up);
            }catch (Exception e){
                e.printStackTrace();
                System.out.println(e);
            }
        }
        System.out.println("结束的时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()).toString());
    }
    private JSONObject getAccessToken() {
        JSONObject jso = new JSONObject();
        try {
            Map<String, Object> hearderMap = new HashMap<>();
            hearderMap.put("Content-Type", "application/x-www-form-urlencoded");
            String url = "http://10.5.78.17:20087/dingding/app/getToken?key=dingaa5kxmcq0p5zyndo&secret=ad65c9c9f3c1de067996b7e3d1e4b87d";
            jso = Httputil.sendHttpGet(url, null, hearderMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return jso;
    }
    /**
     * 字符转换函数
     *
     * @param s
     * @return output:如果字符串为null,返回为空,否则返回该字符串
     */
    public static String nullObject2String(Object s) {
        String str = "";
        try {
            str = s.toString();
        } catch (Exception e) {
            str = "";
        }
        return str;
    }

    private boolean history = false;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if(!history){
            return;
        }
        //日期，含头不含尾
        LocalDate start = LocalDate.of(2023, 4, 12);
        LocalDate end = LocalDate.of(2023, 4, 22);
        while (start.isBefore(end)){
            String dateStr = start.toString();
            Map<String, String> map = new HashMap<>();
            map.put("date", dateStr);
            try {
                this.AttendanceForSTFCrontab(dateStr);
                map.put("status", "success");
            }catch (Exception e){
                map.put("status", "error");
                throw e;
            }finally {
                try {
                    this.attendanceService.insertLog(map);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            start = start.plusDays(1);
        }
    }

    @Scheduled(cron = "1 1 1 * * ?")
    public void run() throws Exception {
        if(history){
            return;
        }
        //日期，含头不含尾
        LocalDate start = LocalDate.now().minusDays(1);
        String dateStr = start.toString();
        Map<String, String> map = new HashMap<>();
        map.put("date", dateStr);
        try {
            this.AttendanceForSTFCrontab(dateStr);
            map.put("status", "success");
        }catch (Exception e){
            map.put("status", "error");
            throw e;
        }finally {
            try {
                this.attendanceService.insertLog(map);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
